/**
 * User: Jinqn
 * Date: 14-04-08
 * Time: 下午16:34
 * 上传图片对话框逻辑代码,包括tab: 远程图片/上传图片/在线图片/搜索图片
 */

(function () {

    var onlineFile;

    window.onload = function () {
        initTabs();
        var attachment = editor.selection.getRange().getClosedNode();
        if (attachment && attachment.tagName && attachment.tagName.toLowerCase() == 'a') {
            $("#upload_button").click(function(){
                parent.layer.open({
                    type: 2,
                    title: '附件上传',
                    shadeClose: false,
                    shade: 0.5,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['98%', '95%'],
                    content: editor.options.uploadUrl + (editor.options.uploadUrl.indexOf("?") > -1 ? "&" : "?") + "uploadMaxLength=" + (1)+"&uploadCallback="+editor.options.uploadAttachmentsCallback
                });
                dialog.close()
            });
        }else{
            parent.layer.open({
                type: 2,
                title: '附件上传',
                shadeClose: false,
                shade: 0.5,
                maxmin: true, //开启最大化最小化按钮
                area: ['98%', '95%'],
                content: editor.options.uploadUrl + (editor.options.uploadUrl.indexOf("?") > -1 ? "&" : "?") + "uploadMaxLength=" + (1000)+"&uploadCallback="+editor.options.uploadAttachmentsCallback
            });
            dialog.close();
        }
        
    };

    /* 初始化tab标签 */
    function initTabs() {
        var tabs = $G('tabhead').children;
        for (var i = 0; i < tabs.length; i++) {
            domUtils.on(tabs[i], "click", function (e) {
                var target = e.target || e.srcElement;
            });
        }
    }
})();